<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">活动参与统计</ui:define>
    <ui:define name="content">

        <h:form>
            <p:dialog header="操作执行中,请稍候" widgetVar="doing" modal="true" closable="false" resizable="false" draggable="false"/>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>
                        <p:commandButton id="flush" value="刷新缓存" icon="fa fa-bolt"
                                         actionListener="#{activityParticipateStatBean.onFlushCache()}"
                                         update="@form"/>
                        <p:columnToggler datasource="statisticRecordDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         onstart="PF('doing').show()"
                                         rendered="#{activityParticipateStatBean.isNormal()}"
                                         update="@form"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         ajax="false">
                            <p:dataExporter type="csv" target="statisticRecordDataTable" fileName="export"
                                            encoding="GBK"/>
                        </p:commandButton>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         rendered="#{activityParticipateStatBean.isNormal()}"
                                         actionListener="#{activityParticipateStatBean.onReset}"
                                         process="@this" update="@form"/>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g-12">
                    <div class="ui-g-12 ui-g-nopad card">
                        <h1>查询条件</h1>

                        <div class="ui-g-1">
                            <p:outputLabel value="时间"/>
                        </div>
                        <div class="ui-g-2">
                            <p:calendar value="#{activityParticipateStatBean.$.startTime}"
                                        locale="#{constants:get('LOCALE')}"
                                        styleClass="autoWidthCalendar"
                                        timeZone="#{constants:get('TIME_ZONE')}"
                                        pattern="#{constants:get('DATE_FORMAT')}"/>
                            <span>—</span>
                            <p:calendar value="#{activityParticipateStatBean.$.endTime}"
                                        locale="#{constants:get('LOCALE')}"
                                        styleClass="autoWidthCalendar"
                                        timeZone="#{constants:get('TIME_ZONE')}"
                                        pattern="#{constants:get('DATE_FORMAT')}"/>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel for="selectUserType" value="用户类型"/>
                        </div>
                        <div class="ui-g-2">
                            <p:selectCheckboxMenu id="selectUserType" value="#{activityParticipateStatBean.$.userType}"
                                                  updateLabel="true" multiple="true" filter="true">
                                <f:selectItems value="#{activityParticipateStatBean.userTypeList}" var="userType"
                                               itemValue="#{userType.userTypeId}" itemLabel="#{userType.userType}"/>
                            </p:selectCheckboxMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel for="selectAD" value="广告位ID"/>
                        </div>
                        <div class="ui-g-2">
                            <p:selectCheckboxMenu id="selectAD" value="#{activityParticipateStatBean.$.adId}"
                                                  updateLabel="true" multiple="true" filter="true" filterMatchMode="contains">
                                <f:selectItems value="#{activityParticipateStatBean.adList}" var="ad"
                                               itemValue="#{ad.advertiseId}" itemLabel="#{ad.advertiseName}"/>
                            </p:selectCheckboxMenu>
                        </div>


                        <div class="ui-g-1">
                            <p:outputLabel for="selectPlatform" value="平台"/>
                        </div>
                        <div class="ui-g-2">
                            <p:selectCheckboxMenu id="selectPlatform" value="#{activityParticipateStatBean.$.platform}"
                                                  updateLabel="true" multiple="true" filter="true" filterMatchMode="contains">
                                <f:selectItems value="#{activityParticipateStatBean.platformList}" var="platform"
                                               itemValue="#{platform.platformCode}" itemLabel="#{platform.platformName}"/>
                            </p:selectCheckboxMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel for="selectActivity" value="活动"/>
                        </div>
                        <div class="ui-g-2">
                            <p:selectCheckboxMenu id="selectActivity" value="#{activityParticipateStatBean.$.activityId}"
                                                  updateLabel="true" multiple="true" filter="true" filterMatchMode="contains">
                                <f:selectItems value="#{activityParticipateStatBean.activityList}" var="activity"
                                               itemValue="#{activity.id}" itemLabel="#{activity.name}(#{activity.id})"/>
                            </p:selectCheckboxMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="产品"/>
                        </div>
                        <div class="ui-g-2">
                            <p:scrollPanel style="width: 100%; height: 135px" mode="native">
                                <p:tree value="#{activityParticipateStatBean.productTreeNode}" var="doc"
                                        selectionMode="checkbox" filter="true" filterMatchMode="contains"
                                        filterBy="#{doc.name}"
                                        selection="#{activityParticipateStatBean.$.selectedProductNodes}">
                                    <p:treeNode>
                                        <h:outputText value="#{doc.name}(#{doc.productId})"/>
                                    </p:treeNode>
                                </p:tree>
                            </p:scrollPanel>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="渠道"/>
                        </div>
                        <div class="ui-g-2">
                            <p:scrollPanel style="width: 100%; height: 156px" mode="native">
                                <p:tree value="#{activityParticipateStatBean.channelTreeNode}" var="channel"
                                        selectionMode="checkbox" filter="true" filterMatchMode="contains"
                                        filterBy="#{channel.channelName}"
                                        selection="#{activityParticipateStatBean.$.selectedChannelNodes}">
                                    <p:treeNode>
                                        <h:outputText value="#{channel.channelName}(#{channel.channelCode})"/>
                                    </p:treeNode>
                                </p:tree>
                            </p:scrollPanel>
                        </div>
                    </div>

                    <div class="ui-g-12 card">
                        <p:dataTable id="statisticRecordDataTable"
                                     style="width: 100%;text-align:center"
                                     var="statisticRecord"
                                     value="#{activityParticipateStatBean.lazyDataModel}"
                                     rows="20"
                                     lazy="true"
                                     paginator="true"
                                     paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                     rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                     emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                     scrollable="true"
                                     reflow="true"
                                     selection="#{activityParticipateStatBean.selectedRecords}"
                                     resizableColumns="true">
                            <p:column headerText="时间">
                                <h:outputText value="#{statisticRecord.date}"/>
                            </p:column>
                            <p:column headerText="大产品" style="text-align:center;">
                                <h:outputText value="#{activityParticipateStatBean.translate(DictionaryCode.LARGE_COMMON_PRODUCT,statisticRecord.parentId)}"/>
                            </p:column>
                            <p:column headerText="产品" style="text-align:center;">
                                <h:outputText value="#{'全部' eq(statisticRecord.productName) ? '全部': activityParticipateStatBean.translateProduct(statisticRecord.productName)}"/>
                            </p:column>
                            <p:column headerText="渠道分类" style="text-align:center;">
                                <h:outputText value="#{activityParticipateStatBean.translate(DictionaryCode.CHANNEL_GROUP,statisticRecord.channelGroup)}"/>
                            </p:column>
                            <p:column headerText="渠道" style="text-align:center;">
                                <h:outputText value="#{'全部' eq (statisticRecord.channelName) ? '全部' : activityParticipateStatBean.translateProductChannel(statisticRecord.channelName)}"/>
                            </p:column>
                            <p:column headerText="平台" style="text-align:center;">
                                <h:outputText value="#{statisticRecord.platform}"/>
                            </p:column>
                            <p:column headerText="用户" style="text-align:center;">
                                <h:outputText value="#{'全部' eq (statisticRecord.userType) ? '全部' : statisticRecord.userType == 0 ? '老用户' : '新用户'}"/>
                            </p:column>
                            <p:column headerText="广告id" style="text-align:center;">
                                <h:outputText value="#{statisticRecord.adId}"/>
                            </p:column>
                            <p:column headerText="活动ID" style="text-align:center;">
                                <h:outputText value="#{statisticRecord.activityId}"/>
                            </p:column>
                            <p:column headerText="活动名称" style="text-align:center;">
                                <h:outputText value="#{statisticRecord.activityName}"/>
                            </p:column>
                            <p:column headerText="甲方池" style="text-align:center;">
                                <h:outputText value="#{activityParticipateStatBean.translate(DictionaryCode.RECOMMEND_POOL_TYPE,statisticRecord.recommendType)}"/>
                            </p:column>
                            <p:column headerText="详情UV" sortBy="#{statisticRecord.showUv}" style="text-align:center;">
                                <h:outputText value="#{statisticRecord.showUv}"/>
                            </p:column>
                            <p:column headerText="详情PV" sortBy="#{statisticRecord.showPv}" style="text-align:center;">
                                <h:outputText value="#{statisticRecord.showPv}"/>
                            </p:column>
                            <p:column headerText="参与UV" sortBy="#{statisticRecord.clickUv}" style="text-align:center;">
                                <h:outputText value="#{statisticRecord.clickUv}"/>
                            </p:column>
                            <p:column headerText="参与PV" sortBy="#{statisticRecord.clickPv}" style="text-align:center;">
                                <h:outputText value="#{statisticRecord.clickPv}"/>
                            </p:column>
                            <p:column headerText="详情>参与" style="text-align:center;">
                                <h:outputText value="#{statisticRecord.participatePercent}"/>
                            </p:column>
                        </p:dataTable>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>